<?php
namespace GFPHP;
if (!defined('__ROOT__')) exit('Sorry,Please from entry!');

/**
 * 路由类
 * 解析网址,实例化控制器
 * 创建时间：2014-08-08 21:39 PGF
 */
class Router
{
    /**
     * @var Router
     */
    public static $router;
    /**
     * @var array
     */
    public $routers = array();

    //======运行方法

    public static function run()
    {
        Hooks::listen('GFPHP_router_start');
        $class = Config::router('driver');
        Loader::driver('routers', $class);
        self::$router = new $class;
        self::$router->controller();
        Hooks::listen('GFPHP_router_end');
    }

    //开始实例化controller

    /**
     * @return array
     */
    public static function get()
    {
        return self::$router->routers;
    }

    /**
     * 根据行为获取链接
     * @param string $action
     * @param bool $get
     * @return array
     */
    public static function url($action='', $get = false)
    {
        return self::$router->_url($action, $get);
    }

    //==解析正确的网址
    /**
     * @param $action
     * @param bool $get
     * @return array
     */
    protected function _url($action, $get = false)
    {
    }

    //==根据路由配置实时获取正确网址

    /**
     * 解析URL
     * @return array
     */
    protected function parse_url()
    {
    }

    //==解析网址

    /**
     *
     */
    private function controller()
    {
        Loader::core('Controller');
        self::$router->routers = $c = self::$router->parse_url();
        Loader::controller(ucfirst(strtolower($c['module'])),ucfirst(strtolower($c['controller'])), $c['method'], $c['var'], true);
    }

    //==获取PathInfo 

}

//====================    END Router.class.php      ========================//